Scripts and expressions.

ZGameEditor has a very simple expression parser. The general syntax is based upon "C"-dialects. 

The following syntax is supported.

Comments:

//this is a single line comment

/*
   this is a 
   multi line 
   comment
*/

Assignments:

[objectname].[propertyname].[propertyindex] = value ;

objectname  - The name of a component is the value of its "Name"-property and is set in the editor. The special objectname "CurrentModel" can be used if the expression written has a Model-component as a parent.

propertyname - The name of the property to assign.

propertyindex - If the property is an indexed property, then the name of the index must be specified. 

For Color-values, this is "R","G","B","A" for the Red/Green/Blue/Alpha components of the color in the range 0 to 1.

For position or vertex-values (such as Model.Position/Rotation/Velocity) the propertyindex is "X","Y","Z" for the value of its corresponding axis.

Example assignments:

PlayerModel.Position.X = 42;
PlayerModel.Position.X = PlayerModel.Position.Y / 2;

MyMaterial.Color.R = 0.5;

PlayerScore += 500;

Other C-style assignments are supported also:

= - normal assignment
+=  - plus-assign: x+=1 is the same as x=x+1
-=  - minus-assign: x-=1 is the same as x=x-1
*=  - multiply-assign: x*=1 is the same as x=x*1
/=  - divide-assign: x/=1 is the same as x=x/1

IF-statements:

if( [condition] ) 
  [one line expression] ;
  
if( [condition] ) {
  //do something if condition is true
} else {
  //do something else if condition is false
}
  
condition - An expression which is evaluted to true or false. Examples:

Operators that are valid in conditions:
> - greater than
>= - greater than or equal
< - less than
<= - less than or equal
|| - OR, statement is true if any of the conditions are true
&& - AND, statement is true if both conditions are true

Example IF-statements:

if(PlayerScore>5000)
  PlayerLives += 1;

if( (App.Time>5) && (PlayerLives<2) ) {
  Difficulty *= 1.2;
  Speed *= 1.2;  
}


Built in mathematical functions:

sin(x)  -  returns the sine of the angle x in radians
sqrt(x)  -  square root of x
cos(x)  - cosine of the angle x in radians.
tan(x)  - tangent of x
abs(x)  - absolute (positive) value of x
rnd()  - returns a random number in the range 0 to 1.
random(base,variance)  - random number in the range base-variance to base+variance
atan2(y,x)  - arctangent angle and quadrant of a given number
noise2(x,y)
noise3(x,y,z)  - 2 and 3 dimensional Perlin Noise. 
frac(x)  - fractional (decimal) part of x
exp(x) - the exponential of x
clamp(x,min,max)  - clamps the value x to be in the range min to max
pow(base,exponent)  - raises base to any power
